﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;

namespace ClassTester.ConditionalFormatting
{
    class ConditionalFormatter
    {
        public enum CondError { Green, Red, Yellow }

        public static void AddCondition(Worksheet sheet, Range c1, Range c2, CondError color, XlFormatConditionOperator condoperator, string value)
        {
            FormatCondition conditionset =
                (FormatCondition)
                (sheet.get_Range(c1, c2)).FormatConditions.Add(XlFormatConditionType.xlCellValue,
                                                               condoperator, value);
            conditionset.Interior.Color = GetColorInHex(color);
        }

        private static int GetColorInHex(CondError color)
        {
            int colorhex = 0x00000000;
            switch (color)
            {
                case CondError.Green:
                    colorhex = 0x003CB371;
                    break;
                case CondError.Red:
                    colorhex = 0x000000FF;
                    break;
                case CondError.Yellow:
                    colorhex = 0x0000A5FF; //geel;
                    break;
                default:
                    colorhex = 0x00000000;
                    break;
            }
            return colorhex;
        }
    }
}
